/*
 * SwingTextArea.fx
 * Author: Yu Min-ting
 * Created on 2009-7-22, 17:54:39
 */

package com.sjtu.fx.tools;

import javafx.ext.swing.SwingComponent;
import javax.swing.JTextArea;

import javax.swing.JComponent;
import javax.swing.JScrollPane;

import java.awt.Color;

import javax.swing.BorderFactory;

import java.awt.Font;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;



public class SwingTextArea extends SwingComponent {

    var jTextArea: JTextArea;
    public var text:String on replace {
        jTextArea.setText(text);
    }
    public var columns:Integer on replace {
        jTextArea.setColumns(columns)
    }
    public var rows:Integer on replace {
        jTextArea.setRows(rows)
    }
    public var editable:Boolean on replace {
        jTextArea.setEditable(editable);
    }

    public override function createJComponent():JComponent{
        jTextArea = new  JTextArea();
        jTextArea.setBackground(Color.getHSBColor(0.57, 0.036, 0.97));
        jTextArea.setBorder(BorderFactory.createRaisedBevelBorder());
        jTextArea.setColumns(columns);
        jTextArea.setRows(rows);

        jTextArea.setLineWrap(true);
        jTextArea.setWrapStyleWord(true);
        jTextArea.setEditable(editable);
        jTextArea.setFont(new Font("Verdana",0,10));
       
        jTextArea.setText(text);
        jTextArea.addKeyListener( KeyListener{
             public override function
            keyPressed(keyEvent:KeyEvent) {

            }

              public override function
            keyTyped(keyEvent:KeyEvent) {

            }

            public override function
            keyReleased( keyEvent:KeyEvent) {
               if (text != jTextArea.getText())
                  text = jTextArea.getText();

            }

        }
        );
        
        return new JScrollPane(jTextArea);
    }


}
